package com.yhjapp.onethingoneyard.onethingoneyard;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.squareup.okhttp.Request;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

/**
 * Created by Administrator on 2017-11-28.
 */

public class ForgotPasswordNextActivity extends AppCompatActivity{
    private ImageView iv_forgot_password_next_back;
    private EditText et_forgot_pwd_newpass;
    private EditText et_forgot_pwd_truenewpass;
    private TextView tv_login_forgotPassword_next_true;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_forgot_password_next);
        iv_forgot_password_next_back= (ImageView) findViewById(R.id.iv_forgot_password_next_back);
        iv_forgot_password_next_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        et_forgot_pwd_newpass= (EditText) findViewById(R.id.et_forgot_pwd_newpass);
        et_forgot_pwd_truenewpass= (EditText) findViewById(R.id.et_forgot_pwd_truenewpass);
        tv_login_forgotPassword_next_true= (TextView) findViewById(R.id.tv_login_forgotPassword_next_true);
        tv_login_forgotPassword_next_true.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoadLogin();
            }
        });
    }

    private void LoadLogin(){
        String token=getIntent().getStringExtra("token");
        String newpwd=et_forgot_pwd_newpass.getText().toString();
        String trueNewpwd=et_forgot_pwd_truenewpass.getText().toString();
        if(newpwd.equals("")){
            Toast.makeText(ForgotPasswordNextActivity.this,"密码不能为空！", Toast.LENGTH_SHORT).show();
        }else if(trueNewpwd.equals("")){
            Toast.makeText(ForgotPasswordNextActivity.this,"确认密码不能为空！", Toast.LENGTH_SHORT).show();
        }
        Log.e("重置","WYBS"+ AUniqueIdentifier.getDeviceId(ForgotPasswordNextActivity.this));
        String url = "http://develop.jhjvip.cn:8080/mall/mobile/users/chgpwd"+"?token="+token+"&newpwd="+newpwd+"&confirmpwd="+trueNewpwd+"&appId="+ AUniqueIdentifier.getDeviceId(ForgotPasswordNextActivity.this);
        Log.e("重置","登录url===="+url);
        OkHttpUtils.get().url(url).build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                LoginBean list = gson.fromJson(response, LoginBean.class);
                if(list.getCode().equals("10000")) {

                    Toast.makeText(ForgotPasswordNextActivity.this, "修改密码成功!", Toast.LENGTH_SHORT).show();
                    Intent intent=new Intent(ForgotPasswordNextActivity.this,LoginActivity.class);
                    startActivity(intent);
                    finish();
                }else {
                    Toast.makeText(ForgotPasswordNextActivity.this, list.getMsg(), Toast.LENGTH_SHORT).show();
                }
            }



        });
    }

}
